package com.xyz.springcloud.service;

import com.xyz.springcloud.Util.IdGeneratorSnowflake;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.*;

/**
 * @author 肖咉卓
 */
@Service
public class OrderService {

    @Resource
    private IdGeneratorSnowflake idGeneratorSnowflake;

    public String getIDBYSnowFlake(){
        ExecutorService threadPool = new ThreadPoolExecutor(
                2,
                (Runtime.getRuntime().availableProcessors()+1),
                2L,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(20),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        for (int i=1;i <= 20;i++){
            threadPool.submit(() ->{
                System.out.println(idGeneratorSnowflake.snowflakeId());
            });
        }
        return "hello snowFlake";
    }
}
